<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>曝光台页面</title>
    <header th:replace="header::html"></header>
    <link th:href="@{/xadmin/lib/layui/css/layui.css}" rel="stylesheet" type="text/css"/>
    <script th:src="@{/xadmin/lib/layui/layui.js}" type="text/javascript"></script>
</head>

<body>

    <div class="layui-fluid">
        <div class="layui-row  layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form  layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="who" id="who" placeholder="请输入被曝光者关键字" autocomplete="off"
                                       class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" id="startDate" placeholder="请选择开始日期"
                                           name="startDate">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" id="endDate" placeholder="请选择结束日期" name="endDate">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="exposureType" id="exposureType" class="layui-select">
                                        <option value="" selected="selected">--仲裁状态--</option>
                                        <option value="11">审核中</option>
                                        <option value="7">已曝光</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="exposureSticky" id="exposureSticky" class="layui-select">
                                        <option value="" selected="selected">--置顶状态--</option>
                                        <option value="1">已置顶</option>
                                        <option value="0">未置顶</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="search"><i
                                        class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-body ">
                        <table class="layui-hide" id="exposureTable" lay-filter="exposureTable" ></table>
                    </div>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
                        {{#  if(d.pid ===7 && d.sticky ==='1'){ }}
                             <a class="layui-btn layui-btn-xs" lay-event="delete" >删除</a>
                            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="cancelSticky" >取消置顶</a>
                        {{#  } else if(d.pid ===7 && d.sticky ==='0'){ }}
                        <a class="layui-btn layui-btn-xs" lay-event="delete" >删除</a>
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="doSticky" >置顶</a>
                        {{#  } else { }}
                        <a class="layui-btn layui-btn-xs" lay-event="review-yes" >通过</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="review-no">不通过</a>
                        {{#  } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</body>
<script>

	layui.use('laydate', function () {
		var laydate = layui.laydate;
		//选中后的回调
		laydate.render({
			elem: '#startDate'
			, done: function (value, date) {
				// layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
			}
		});

		laydate.render({
			elem: '#endDate'
			, done: function (value, date) {
				// layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
			}
		});
	});


	layui.use(['table','form','layer'], function () {
		var table = layui.table,
            layer=layui.layer,
			form = layui.form;
		table.render({
			elem: '#exposureTable'
			, url: '/api-back/exposure/exposureDeploy' //数据接口
			, page: true //开启分页
			, cellMinWidth: 80 //全局定义常规单元格的最小宽度
			, limits:[10,20]
			, limit:10
			, response: {
				dataName: 'datas' //规定数据列表的字段名称，默认：data
			}
			, cols: [
				[
					{type:'numbers' ,align:'center'}
					,{field:'eid', align:'center',title: '曝光表id',style:'display:none;'}
					,{field:'oid', align:'center',title: '订单id',style:'display:none;'}
					,{field:'ereason', title: '曝光原因',width: '23%',align:'center',style:'color:red;'}
					,{field:'uaccount',align:'center',width: '15%',title: '被曝光商家/个体'}
					,{field:'estarttime', align:'center',width: '10%', title: '曝光时间'}
					,{field:'eendtime', align:'center',width: '10%', title: '公示结束时间'}
					,{field:'pid', align:'center', title: '状态',width: '9%',templet:function (msg) {
						return msg.pid== '7'?"已曝光":"审核中";
					}}
					,{field:'sticky', align:'center', title: '置顶状态',width: '9%',templet:function (msg) {
						return msg.sticky== '1'?"已置顶":"未置顶";
					}}
					,{ fixed: 'right', title: '操作',  align: 'center',width: 220, toolbar: '#barDemo'}

				]
			],
			done: function () {
				//checkPermission();
			}

		});
		$('table.layui-table thead tr th:eq(1)').addClass('layui-hide');//隐藏的曝光表id表头
		$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏订单表id的表头
		//监听行工具事件
		table.on('tool(exposureTable)', function(obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
			var data = obj.data ,//获得当前行数据
				layEvent = obj.event, //获得 lay-event 对应的值
                eid=data.eid,
                oid=data.oid;
			if(layEvent === 'delete') {
				layer.confirm('确定要删除曝光公示吗？删除后不可恢复',function (index) {
					$.ajax({
						type:"post",
						url:'/api-back/exposure/exposure-delete',
						data:{"eid":eid},
						success:function (msg) {
							if (msg === "success") {
								layer.msg("删除成功",{icon:1});
								$(".layui-laypage-btn")[0].click();
							} else {
								layer.msg("删除失败，请重试",{icon:2})
							}
						},
						error:function (msg) {
							layer.open({
								type:2,
								content: "/404.html",
								area:['1000px','600px'],
								title:'权限不允许进行访问'
							})
						}
					})
				})
			}
			else if(layEvent === 'review-yes'){
				layer.confirm('确定通过审核吗？',function (index) {
					$.ajax({
						url:'/api-back/exposure/exposure-yes',
						type:"post",
						data:{"eid":eid,"oid":oid},
						success:function (msg) {
							if (msg === "success") {
								layer.msg("审核成功，提交曝光公示",{icon:1});
								$(".layui-laypage-btn")[0].click();
							} else {
								layer.msg("审核操作失败，请重试",{icon:2})
							}
						},
						error:function (msg) {
							layer.open({
								type:2,
								content: "/404.html",
								area:['1000px','600px'],
								title:'权限不允许进行访问'
							})
						}
					})
				})
			}
			else if (layEvent === 'review-no') {
				layer.confirm('审核不通过吗？',function (index) {
					$.ajax({
						url:'/api-back/exposure/exposure-no',
						type:"post",
						data:{"eid":eid,"oid":oid},
						success:function (msg) {
							if (msg === "success") {
								layer.msg("审核不通过，订单交易完成",{icon:1});
								obj.del(); //删除对应行（tr）的DOM结构
								$(".layui-laypage-btn")[0].click();
							} else {
								layer.msg("审核操作失败，请重试",{icon:2})
							}
						},
						error:function (msg) {
							layer.open({
								type:2,
								content: "/404.html",
								area:['1000px','600px'],
								title:'权限不允许进行访问'
							})
						}
					})
				})
			}
			else if (layEvent === 'details') {
                $.ajax({
                    url:'/api-back/exposure/exposure-details',
	                type:"post",
                    data:{"oid":oid},
                    success:function (msg) {
	                    layer.open({
		                    type: 1 //Page层类型
		                    ,area: ['600px', '400px']
		                    ,title: '查看订单详情'
		                    ,shade: 0.3 //遮罩透明度
		                    ,anim: 1 //0-6的动画形式，-1不开启
		                    ,content:
                                '<div style="padding:50px;font-size: 15px"><div><p>雇主名称：'+msg.uname+'&nbsp;(ID:'+msg.nuseraccount+')</p></div><br><div><p>订单标题：'+msg.ntitle+'</p></div><br><div><p>订单内容：'+msg.ncontent+'</p></div><br><div><p>订单要求：'+msg.ndemand+'</p></div><br><div><p>订单金额：'+msg.nmoney+'(CNY)</p></div><br><div><p>时间：'+msg.nstarttime+'-至-'+msg.nendtime+'</p></div></div>'
	                    });
                    },
                    error:function (msg) {
	                    layer.open({
		                    type:2,
		                    content: "/404.html",
		                    area:['1000px','600px'],
		                    title:'权限不允许进行访问'
	                    })
                    }
                })
			}
			else if (layEvent === 'cancelSticky') {
				$.ajax({
					url:'/api-back/exposure/exposure-cancelSticky',
					type:"post",
					data:{"eid":eid},
					success:function (msg) {
						if (msg === "success") {
							layer.msg("取消置顶成功",{icon:1});
							$(".layui-laypage-btn")[0].click();
						} else {
							layer.msg("取消置顶失败，请重试",{icon:2})
						}
					},
					error:function (msg) {
						layer.open({
							type:2,
							content: "/404.html",
							area:['1000px','600px'],
							title:'权限不允许进行访问'
						})
					}
				})
			}
			else if (layEvent === 'doSticky') {
				$.ajax({
					url:'/api-back/exposure/exposure-doSticky',
					type:"post",
					data:{"eid":eid},
					success:function (msg) {
						if (msg === "success") {
							layer.msg("置顶成功",{icon:1});
							$(".layui-laypage-btn")[0].click();
						} else {
							layer.msg("置顶失败，请重试",{icon:2})
						}
					},
					error:function (msg) {
						layer.open({
							type:2,
							content: "/404.html",
							area:['1000px','600px'],
							title:'权限不允许进行访问'
						})
					}
				})
			}
		});

		//搜索
		form.on('submit(search)', function (data) {
			var field = data.field;
			if (dateCompare(field.startDate, field.endDate)) {
				table.render({
					elem: '#exposureTable'
					, url: '/api-back/exposure/exposureDeploy' //数据接口
					, page: true //开启分页
					, limits:[10,20]
					, limit:10
					, where: {
						"who": field.who,
						"starttime": field.startDate,
						"endtime": field.endDate,
                        "exposureType":field.exposureType,
						"exposureSticky":field.exposureSticky
					}
					, response: {
						dataName: 'datas' //规定数据列表的字段名称，默认：data
					}
					, cols: [
						[
							{type:'numbers' ,align:'center'}
							,{field:'eid', align:'center',title: '曝光表id',style:'display:none;'}
							,{field:'oid', align:'center',title: '订单id',style:'display:none;'}
							,{field:'ereason', title: '曝光原因',width: '23%',align:'center',style:'color:red;'}
							,{field:'uaccount',align:'center',width: '15%',title: '被曝光商家/个体'}
							,{field:'estarttime', align:'center',width: '10%', title: '曝光时间'}
							,{field:'eendtime', align:'center',width: '10%', title: '公示结束时间'}
							,{field:'pid', align:'center', title: '状态',width: '9%',templet:function (msg) {
								return msg.pid== '7'?"已曝光":"审核中";
							}}
							,{field:'sticky', align:'center', title: '置顶状态',width: '9%',templet:function (msg) {
								return msg.sticky== '1'?"已置顶":"未置顶";
							}}
							,{ fixed: 'right', title: '操作',  align: 'center',width: 220, toolbar: '#barDemo'}

						]
					]
				});
				$('table.layui-table thead tr th:eq(1)').addClass('layui-hide');//隐藏的曝光表id表头
				$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏订单表id的表头
			} else {
				layer.msg("您的日期不正确，请重新输入！",{icon:2});
			}
			return false;
		});
		//checkPermission();
	});

	function dateCompare(startDate, endDate) {
		var oDate1 = new Date(startDate);
		var oDate2 = new Date(endDate);
		if (oDate1 > oDate2) {
			return false;
		} else {
			return true;
		}
	}


</script>
</html>